<?php
/**
 * @author Zwc
 * Created On 2022/6/14 22:12
 */

namespace app\middleware;


use app\admin\enums\DelFlag;
use app\common\models\UserModel;
use app\common\models\UsersModel;
use app\common\services\ApiJsonWebToken;

class Authorization
{
	public function handle($request, \Closure $next)
	{
		$token = $request->header('Authorization');
        if(empty($token)) {
			return json(['code' => -1,'msg' => 'Authorization不能为空']);
		}else {
            $tokenService = new ApiJsonWebToken();
            $tokenData = $tokenService->verifyToken($token);
            if($tokenData) {
                $request->userId = $tokenData['uuid'];
            }
        }
		return $next($request);
	}
}